<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    账号：<input type="text" name='username' id='uname'>
    密码: <input type="text" name='password'id='pwd'>
    <button type="button" onclick="get1()">get请求不带参数</button>
    <button type="button" onclick="get2()">
    get请求带参数</button>
</body>
<script>
    function get1(){
        var xhr = new XMLHttpRequest()
        xhr.open('get','http://localhost:3000/get1')
        xhr.send()
        xhr.onreadystatechange = function(){
            if(xhr.readyState == 4 && xhr.status == 200){
                console.log(xhr.responseText);
            }
        }
    }
    function get2(){
        var uname = document.getElementById('uname').value
        var pwd = document.getElementById('pwd').value
        var xhr = new XMLHttpRequest()
        xhr.open('get', `http://localhost:3000/get2?username=${uname}&password=${pwd}`)
        xhr.send()
        xhr.onreadystatechange = function(){
            if(xhr.responseText == 4 && xhr.status == 200){
                console.log(xhr.responseText);
            }
        }
    }
</script>
</html>